{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ea14f00-ee19-4334-847c-c5e8e6d88b60",
   "metadata": {
    "tags": [
     "remove_cell"
    ]
   },
   "outputs": [],
   "source": [
    "import datapane as dp\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "473a8e8f-b087-4032-9cee-3d4845338fcb",
   "metadata": {},
   "source": [
    "::: datapane.Table"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "34cd1f47-07be-4dc1-a579-94802af5b756",
   "metadata": {
    "tags": [
     "remove_cell"
    ]
   },
   "source": [
    "The Table block takes a pandas DataFrame and renders an HTML table in your app.\n",
    "\n",
    "!!! info\n",
    "    `Table` is the best option for displaying multidimensional DataFrames, as `DataTable` will flatten your data."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b611cf1-35b9-4d42-928a-3f456608c0f9",
   "metadata": {},
   "source": [
    "### Simple Table from DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "022b64ed-6566-43cb-8ca7-9024b9313748",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "df = pd.DataFrame(\n",
    "    {\n",
    "        \"A\": np.random.normal(-1, 1, 5),\n",
    "        \"B\": np.random.normal(1, 2, 5),\n",
    "    }\n",
    ")\n",
    "\n",
    "dp.Table(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ffdc3e7-6933-41da-8be2-8ad34818a86e",
   "metadata": {},
   "source": [
    "### Styled Table from DataFrame"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "96deac01-960a-43d2-88ff-896b2bbb84a6",
   "metadata": {},
   "source": [
    "If your DataFrame includes [DataFrame Styles](https://pandas.pydata.org/pandas-docs/stable/user\\_guide/style.html), these will be included in your app. DataFrame styles allow you create custom formatted tables; for instance, to show trends, highlight cells, add bar charts, or display correlations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "714989ec-f913-4698-8aba-8b180b659c8f",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "df = pd.DataFrame({\"A\": np.linspace(1, 10, 10)})\n",
    "df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list(\"BCDE\"))], axis=1)\n",
    "\n",
    "dp.Table(df.style.background_gradient(cmap=\"viridis\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f1c7998-cd23-45c7-89e1-4b65de0132a3",
   "metadata": {
    "tags": []
   },
   "source": [
    "::: datapane.DataTable\n",
    "    options:\n",
    "          members:\n",
    "              - __init__"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d29b3ade-b8ff-45b0-b1a3-5eb071e64f1a",
   "metadata": {},
   "source": [
    "### Simple DataTable from DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1188d9a-23d9-4481-acdb-decf5927f9e9",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "df = pd.DataFrame(\n",
    "    {\n",
    "        \"A\": np.random.normal(-1, 1, 5000),\n",
    "        \"B\": np.random.normal(1, 2, 5000),\n",
    "    }\n",
    ")\n",
    "\n",
    "dp.DataTable(df)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "aee61ea2-d803-481b-af40-49174b11e16b",
   "metadata": {},
   "source": [
    "### Running Queries on DataTable\n",
    "\n",
    "You can run SQL queries on your datatable if you need more advanced filtering & calculations. In the previous example, if we wanted to show only the rows which had a value A > 0.5, we would write the following (note that `$table` is the builtin table name and cannot be changed):\n",
    "\n",
    "```sql\n",
    "SELECT * FROM $table\n",
    "WHERE A > 0.5\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01ba5648-287b-4c69-a636-b9c40e8eeae2",
   "metadata": {},
   "source": [
    "::: datapane.BigNumber"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d8505aa-6027-4fca-9093-e08edb11e138",
   "metadata": {},
   "source": [
    "### Simple BigNumber"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c43efe11-a399-40ca-bc40-9b3102c5ca74",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "dp.BigNumber(heading=\"Simple Statistic\", value=100)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee31d8af-460a-4f88-a666-5614493fa329",
   "metadata": {},
   "source": [
    "### BigNumber with change indicators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afb74c34-1aeb-406d-b3a4-4ec302fa9af1",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "dp.Group(\n",
    "    dp.BigNumber(\n",
    "        heading=\"Percentage points\",\n",
    "        value=\"84%\",\n",
    "        change=\"2%\",\n",
    "        is_upward_change=True,\n",
    "    ),\n",
    "    dp.BigNumber(\n",
    "        heading=\"Percentage points\",\n",
    "        value=\"84%\",\n",
    "        change=\"2%\",\n",
    "        is_upward_change=False,\n",
    "    ),\n",
    "    dp.BigNumber(\n",
    "        heading=\"Points\",\n",
    "        value=\"1234\",\n",
    "        change=\"200\",\n",
    "        is_upward_change=True,\n",
    "    ),\n",
    "    dp.BigNumber(\n",
    "        heading=\"Points\",\n",
    "        value=\"1234\",\n",
    "        change=\"200\",\n",
    "        is_upward_change=False,\n",
    "    ),\n",
    "    columns=2,\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
